package com.qdsg.ysg.doctor.ui.dialog;//package com.qdsg.ysg.doctor.ui.dialog;
//
//import android.app.Dialog;
//import android.graphics.drawable.ColorDrawable;
//import android.os.Bundle;
//import android.support.annotation.NonNull;
//import android.support.annotation.Nullable;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.Window;
//import android.view.WindowManager;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//
//import com.rest.business.RestProxy;
//import com.rest.response.DepartmentResponse;
//import com.rest.response.DoctorResponse;
//import com.rest.response.HospitalResponse;
//import com.rest.response.ScheduleResponse;
//import com.rest.response.TimeResponse;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import com.qdsg.ysg.doctor.R;
//import com.qdsg.ysg.doctor.base.BaseDialogFragment;
//import com.qdsg.ysg.doctor.ui.widget.CustomPopWindow;
//
///**
// * Created by Administrator on 2017/11/23.
// */
//
//public class SelectHospitalDialogForConsultationFragment extends BaseDialogFragment {
//
//    public static SelectHospitalDialogForConsultationFragment newInstance() {
//        return new SelectHospitalDialogForConsultationFragment();
//    }
//
//    private Dialog mDialog;
//    private OnItemClickListener mListener;
//    private ImageView btn_cancel;
//    private TextView btn_hospital, btn_department, btn_doctor,btn_save;
//    private CustomPopWindow mListPopWindow;
//    private MyAdapter adapter;
//    private List<DateContainer> list = new ArrayList<>();
//    public static final int HOSPITAL_CODE = 0;
//    public static final int DEPARTMENT_CODE = 1;
//    public static final int DOCTOR_CODE = 2;
//    private long hospital_id,department_id,doctor_id;
//    private String hospital_name,department_name,doctor_name;
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        View view = inflater.inflate(R.layout.dialog_select_hospital_consultation, container);
//        btn_cancel = view.findViewById(R.id.btn_cancel);
//        btn_cancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dismiss();
//            }
//        });
//        btn_hospital = view.findViewById(R.id.btn_hospital);
//        btn_department = view.findViewById(R.id.btn_department);
//        btn_doctor = view.findViewById(R.id.btn_doctor);
//        btn_save = view.findViewById(R.id.btn_save);
//
//        btn_hospital.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showPopListView(btn_hospital,HOSPITAL_CODE);
//            }
//        });
//
//        btn_department.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showPopListView(btn_department,DEPARTMENT_CODE);
//            }
//        });
//
//        btn_doctor.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showPopListView(btn_doctor,DOCTOR_CODE);
//            }
//        });
//
//        btn_save.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mListener.onConfirm(hospital_name,department_name,doctor_name,hospital_id,department_id,doctor_id);
//            }
//        });
//
//
//        return view;
//    }
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//    }
//
//    @Override
//    @NonNull
//    public Dialog onCreateDialog(Bundle savedInstanceState) {
//        mDialog = super.onCreateDialog(savedInstanceState);
//        mDialog.setCancelable(false);
//        Window window = mDialog.getWindow();
//        if (window != null) {
//            window.setGravity(Gravity.CENTER);
////            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
////            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        }
//        return mDialog;
//    }
//
//
//    @Override
//    public void onActivityCreated(Bundle savedInstanceState) {
//        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//        super.onActivityCreated(savedInstanceState);
//        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));
//        getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
//    }
//
//    public OnItemClickListener getmListener() {
//        return mListener;
//    }
//
//    public void setmListener(OnItemClickListener mListener) {
//        this.mListener = mListener;
//    }
//
//
//    public interface OnItemClickListener {
//
//        void onConfirm(String text,String text1,String text2, long hospitalId,long deptId,long doctorId);
//    }
//
//    public boolean isShowing() {
//        return mDialog != null && mDialog.isShowing();
//    }
//
//
//    private void showPopListView(View view, int type) {
//        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.pop_list, null);
//        RecyclerView recyclerView = contentView.findViewById(R.id.recyclerView);
//        recyclerView.setLayoutParams(new LinearLayout.LayoutParams(view.getMeasuredWidth(), LinearLayout.LayoutParams.WRAP_CONTENT));
//        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        adapter = new MyAdapter(type);
//        recyclerView.setAdapter(adapter);
//        adapter.notifyDataSetChanged();
//        switch (type) {
//            case HOSPITAL_CODE:
//                getHospital();
//                break;
//            case DEPARTMENT_CODE:
//                getDepartment();
//                break;
//            case DOCTOR_CODE:
//                getDoctor();
//                break;
//        }
//
//        //创建并显示popWindow
//        mListPopWindow = new CustomPopWindow.PopupWindowBuilder(getActivity())
//                .setView(contentView)
//                .size(view.getWidth(), 0) // 显示大小
//                .create()
//                .showAsDropDown(view, Gravity.NO_GRAVITY, 0, 0);
//    }
//
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        int type;
//
//        public MyAdapter(int type) {
//            this.type = type;
//        }
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyAdapter.Holder myHolder = new MyAdapter.Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_textview, parent, false));
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(MyAdapter.Holder holder, final int position) {
//            holder.text.setText(list.get(position).name);
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    switch (type) {
//                        case HOSPITAL_CODE:
//                            btn_hospital.setText(list.get(position).name);
//                            btn_department.setText("");
//                            btn_doctor.setText("");
//                            hospital_name = list.get(position).name;
//                            hospital_id = list.get(position).id;
//                            mListPopWindow.dissmiss();
//                            break;
//                        case DEPARTMENT_CODE:
//                            btn_department.setText(list.get(position).name);
//                            btn_doctor.setText("");
//                            department_name = list.get(position).name;
//                            department_id = list.get(position).id;
//                            mListPopWindow.dissmiss();
//                            break;
//                        case DOCTOR_CODE:
//                            btn_doctor.setText(list.get(position).name);
//                            doctor_id = list.get(position).id;
//                            doctor_name = list.get(position).name;
//                            mListPopWindow.dissmiss();
//                            break;
//                    }
//                }
//            });
//        }
//
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView text;
//
//            public Holder(View itemView) {
//                super(itemView);
//                text = (TextView) itemView.findViewById(R.id.text);
//            }
//        }
//    }
//
//    private void getHospital() {
//        RestProxy.getInstance().getHospitalConsultation(new Observer<HospitalResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(HospitalResponse hospitalResponse) {
//                list.clear();
//                for (HospitalResponse.Hospital hospital : hospitalResponse.data.records) {
//                    DateContainer dateContainer = new DateContainer();
//                    dateContainer.id = hospital.hosId;
//                    dateContainer.name = hospital.hosName;
//                    list.add(dateContainer);
//                }
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//    private void getDepartment(){
//        RestProxy.getInstance().getDepartmentConsultation(hospital_id, new Observer<DepartmentResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(DepartmentResponse departmentResponse) {
//                list.clear();
//
//                for (DepartmentResponse.Department department : departmentResponse.data.records) {
//                    DateContainer dateContainer = new DateContainer();
//                    dateContainer.id = department.deptId;
//                    dateContainer.name = department.deptName;
//
//                    list.add(dateContainer);
//                }
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//
//    }
//
//    private void getDoctor(){
//        RestProxy.getInstance().getDoctorConsultation(hospital_id, department_id, new Observer<DoctorResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(DoctorResponse doctorResponse) {
//                list.clear();
//                for (DoctorResponse.Doctor doctor : doctorResponse.data.records) {
//                    DateContainer dateContainer = new DateContainer();
//                    dateContainer.id = doctor.docId;
//                    dateContainer.name = doctor.docName;
//                    list.add(dateContainer);
//                }
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//
//    class DateContainer {
//        String name;
//        long id;
//    }
//
//}
